package chances.declare.repo;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import chances.declare.entity.UnitContent;
import chances.declare.web.MergerModel;
import chances.declare.web.UnitContentCPContent;

/**
*@Author Guoyh
*@Date 2017年7月26日 下午5:25:19
*chances.declare.repo
*/

public interface UnitContentRepository extends JpaRepository<UnitContent, Long> {

    @Query("from UnitContent")
    public Page<UnitContentCPContent> search(MergerModel model, Pageable pageable);

    @Query("from UnitContent")
    public List<UnitContentCPContent> exportExcel(MergerModel model, Pageable pageable);

    @Query("from UnitContent")
    public Page<UnitContentCPContent> adoptDeclareSearch(MergerModel model, Pageable pageable);

    @Query("select u from UnitContent u where u.adoptCpContentId=null and u.name like %:name%")
    public List<UnitContent> findByNameLike(@Param("name") String name);

    @Query("select u from UnitContent u where u.name = :name")
    public List<UnitContent> findByName(@Param("name") String name);

    @Query("select new chances.declare.web.UnitContentCPContent(c,u) from CPContent c,UnitContent u where u.id=c.unitContentId")
    public Page<UnitContentCPContent> getUnitContentCPContent(Pageable pageable);

}
